<template>
  <div id="app">
    <router-view>

    </router-view>
       <!--  分享 :visible.sync="dialogshare" -->
   <el-dialog  title="登录"  width="40%" :visible.sync="show" :close-on-click-modal="false" :before-close="handleClose">
    <el-form :model="param" :rules="rules" ref="login" label-width="0px" class="ms-content">
                    <el-form-item prop="account">
                        <el-input v-model="param.account" placeholder="account">
                            <el-button slot="prepend" icon="el-icon-lx-people"></el-button>
                        </el-input>
                    </el-form-item>
                    <el-form-item prop="password">
                        <el-input
                            type="password"
                            placeholder="password"
                            v-model="param.password"
                            @keyup.enter.native="submitForm()"
                        >
                            <el-button slot="prepend" icon="el-icon-lx-lock"></el-button>
                        </el-input>
                    </el-form-item>
                    <div class="login-btn">
                        <el-button type="primary" @click="submitForm()">登录</el-button>
                    </div>
                </el-form>
    </el-dialog>
    <!-- <alone-uploader/> -->
  </div>
</template>
<script>
// import uploadFile from './common/uploads/GlobalUploader';
// import aloneUploader from './common/uploads/AloneUploader';
import bus from '@/common/bus';
import { mapState } from 'vuex';
export default {
  // components: { uploadFile,aloneUploader},
  name: "waters",
  computed: {
    ...mapState({
      showlogin: state =>state.app.showlogin
    })
  },
  watch: {
    showlogin:{deep:true,handler:function(value){
      console.log("sdf",value)
      if(value==true){
        this.show=true
      }    
    }} 
  },
  data() {
    return {
      show:false,
      showtext:222,
      isMobile:this.$isMobile,
            param: {
                account: '',
                password: '',
            },
            rules: {
                account: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
                password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
            },
    };
  }, 
  created() {
   
    // bus.$on('showlogin', msg => {
    //   this.show = msg;
    // });
  },
  methods: {

    handleClose(done) {      
      this.$store.dispatch("app/setShowlogin", false);
          done();
     },
    submitForm() {
            const loading = this.$loading({text: '登录中'});
            this.$http.post(this.$API.LOGIN,this.param)
            .then((res)=>{
                loading.close();
                console.log('登录信息',res)
                if(res.code == 1){
                   window.sessionStorage.setItem('jqzxUserId', res.data.id)
                    window.sessionStorage.setItem('userName',res.data.account);
                    window.localStorage.setItem('userInfo',JSON.stringify(res.data));
                    // if(this.isMobile){
                    //     Toast.success('登录成功');
                    // }else{
                    //     this.$message.success('登录成功');
                    // }
                    // this.$router.push('/');
                    this.show=false;
                }else{
                    if(this.isMobile){
                        Toast.fail(res.msg);
                    }else{
                        this.$message.error(res.msg);
                    }
                }
            })
            .catch((err)=>{
                    this.$message.error('');
                    console.log('error submit!!');
                    return false;
            })
        },
        getQueryVariable(variable) {
            var query = window.location.hash,vars=[];
            if(query && query.indexOf('?')!==-1){
                 vars = query.split("?");
            }
            for (var i = 0; i < vars.length; i++) {
                var pair = vars[i].split("=");
                if (pair[0] == variable) { return decodeURIComponent(pair[1]); }
            }
            return '';
        }
    
  }
};
</script>